package com.leminhtrinh.mycash;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.leminhtrinh.mycash.model.CashAccount;
import com.leminhtrinh.mycash.model.CashCategory;
import com.leminhtrinh.mycash.model.CashDataSource;
import com.leminhtrinh.mycash.model.CashTransaction;

public class MainActivity extends Activity {
	private CashDataSource cashDataSource;
	private EditText numberText;

	private String descriptionText;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		numberText = (EditText) findViewById(R.id.numberText);
		cashDataSource = new CashDataSource(this);
		cashDataSource.open();
		List<CashTransaction> transactions = cashDataSource
				.getAllTransactions();
		List<CashAccount> accounts = cashDataSource.getAllAccounts();
		List<CashCategory> categories = cashDataSource.getAllCategories();
		for (CashTransaction ct : transactions) {
			cashDataSource.deleteTransaction(ct);
		}
		cashDataSource.createTransaction(2.3, 0, 0, "LIDL", null, 0, 2012, 12,
				05, 1);
		Log.d("Cash activities", cashDataSource.getAllTransactions().toString());
		cashDataSource.close();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	// This method is called at button click because we assigned the name to the
	// "OnClick property" of the button
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.inButton:
			onIncomeButtonClick();
			break;
		case R.id.outButton:
			onOutcomeButtonClick();
			break;
		case R.id.dateTextView:
			onDateClick();
			break;
		case R.id.detailsTextView:
			onDetailsClick();
			break;
		}
	}

	private void onIncomeButtonClick() {

	}

	private void onOutcomeButtonClick() {
		cashDataSource.createTransaction(
				Double.parseDouble(numberText.getText().toString()), 0, 0, "REAL",
				descriptionText, 0, 2012, 12, 12, 1);
	}

	private void onDateClick() {

	}

	private void onDetailsClick() {

	}
}
